#include <iostream>
#include <vector>
#include <stack>
#include <string>

using namespace std;

int calPoints(vector<string>& operations) {
    vector<int> st; int c = 0;
    for(auto i = operations.begin(); i != operations.end(); i++){
        if(*i == "+"){
            int t = *(st.end() - 1) + *(st.end() - 2);
            st.push_back(t);
        }else if (*i == "D"){
            int t = *(st.end() - 1) * 2;
            st.push_back(t);
        }else if (*i == "C"){
            st.pop_back();
        }else{
            st.push_back(stoi(*i));
        }
    }
    for(auto i = st.begin(); i != st.end(); i++){
        c += *i;
    }
    return c;
}

int main(){
    vector<string> ops = {"5","2","C","D","+"};
    cout << calPoints(ops) << endl;
    return 0;
}
